#ifndef __BUOLA_SCENE_CSCENE_H__
#define __BUOLA_SCENE_CSCENE_H__

#include <buola/scene.h>
#include <buola/scene/cworld.h>
#include <BulletDynamics/ConstraintSolver/btTypedConstraint.h>
#include <BulletSoftBody/btSoftBody.h>

namespace buola { namespace scene {

class CScene : public UShared
{
    struct SPhysics;
    
public:
    CScene(bool pSoftBodies=false,bool pGravity=true);
protected:
    virtual ~CScene();

public:
    PWorld World()   {   return mWorld;  }
    void Render(CRenderContext &pContext);
    void CollectPolygons(std::vector<mat::CVec3d> &pPoints,std::vector<mat::CVec3d> &pNormals,std::vector<int> &pFaces);
    void Update();
    
    void AddBody(PRigidBody pBody);
    void AddBody(PSoftBody pBody);
    void AddConstraint(btTypedConstraint *pConstraint);
    void StepPhysics(double pTime=1.0/120.0,int pMaxSteps=1,double pStepTime=1.0/120.0);
    btSoftBodyWorldInfo &SoftBodyWorldInfo();
    
private:
    SPhysics &Physics();
    
private:
    PWorld mWorld;
    std::unique_ptr<SPhysics> mPhysics;
    bool mSoftBodies;
    bool mGravity;
    std::vector<PSoftBody> mSoftBodyList;
};

/*namespace scene*/ } /*namespace buola*/ }

#endif